package com.originit.product.server.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.originit.product.server.mq.StreamInterface;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
@Slf4j
public class TestController {

    @Autowired
    StreamInterface streamInterface;

    @HystrixCommand(fallbackMethod = "fallback",commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1000" )
    })
    @RequestMapping("/send")
    public String sendMessage() {
        streamInterface.output().send(MessageBuilder.<Object>withPayload("你好呀").build());
        throw new RuntimeException();
    }

    private String fallback () {
        return "不好意思";
    }
}
